//
//  TTotheJsonModel.h
//  TaTogether
//
//  Created by 九月 on 8/21/24.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

#define ModelDelegate(delegate) @protocol delegate <NSObject>    @end
#define ON_MESSAGE(__class,__model,sender)   -(void)message_##__class##_##__model:(id)sender

//接口返回状态判断
#define MSG_ERROR(error,status,message) \
if (error || status != 1)\
{\
  [SVProgressHUD showErrorWithStatus:error ? error:message];\
  return;\
}\


typedef void ( *ImpFuncType )( id a, SEL b,id c,...);
typedef void (^ModelBolck)(id model,NSString *error);
typedef void (^Exception)(void);
typedef enum{
    
    HttpTypeGet,
    HttpTypePost,
    HttpTypePostByToken
    
} HttpsType;
/**
 JSMultipageDelegate代理用于多页加载数据
 */
@protocol JSMultipageDelegate

@optional

/**
 加载第一页
 */
-(void)loadFirstPage;

/**
 加载下一页
 */
-(void)loadNextPage;

-(void)didFinishedLoad:(id)model error:(NSString *)error;

//@property(nonatomic,copy,setter=requestCallBack:) void(^RESULT)(id);

@end

@interface TTotheJsonModel : NSObject<JSMultipageDelegate>{
   
@public  __weak id _observer;  //回条接收者
    NSString *_cacheExt; //模型缓存扩展名
    NSString *_api;
    NSInteger pageNo;
    NSInteger pageSize;
    BOOL hasNextPage;
}

/**
 创建模型对象
 
 @param observe 事件监听对象
 @return BaseMode实例
 */
+(instancetype)modelWithObserve:(id)observe;
+(instancetype)modelWithObserve:(id)observe ext:(NSString *)cacheExt;
+(void)model_POST_Token:(NSString *)urlString paramtter:(NSDictionary *)paras result:(ModelBolck)resultBlock;
+(void)model_POST:(NSString *)urlString paramtter:(NSDictionary *)paras result:(ModelBolck)resultBlock;
+(void)model_GET:(NSString *)urlString paramtter:(NSDictionary *)paras result:(ModelBolck)resultBlock;
/**
 图片上传
 
 @param urlString 请求url
 @param paras 请求参数
 @param images 需要上传的图片数组(数组元素为NSData类型)
 @param resultBlock 请求结果回条
 */
+(void)model_upload:(NSString *)urlString paramtter:(NSDictionary *)paras images:(NSArray *)images result:(ModelBolck)resultBlock;
-(TTotheJsonModel*(^)(NSString *api))API;
-(TTotheJsonModel*(^)(Class cls))CLS;
-(TTotheJsonModel*(^)(NSString *url))URL;
-(TTotheJsonModel*(^)(id paras))PARA;
-(TTotheJsonModel*(^)(id paras))APPEND;
-(TTotheJsonModel*(^)(HttpsType))SEND;
//返回参数值字典
-(NSDictionary *)parameters;
//对结果数据判断
void ESTIMATE(BOOL condition,Exception error,Exception sucess);

/**
 将数据拷贝到模型
 
 @param data json数据
 */
-(void)copyDataToSelf:(id)data;

/**
 模型归档
 */
-(void)saveCache;

/**
 加载本地归档模型
 
 @return 返回一个BaseModel模型(没有缓存返回nil)
 */
-(id)loadCache;
//+(id)loadCache:(NSString *)cacheExt;
/**
 删除本地归档模型数据
 */
-(void)deleteCache;


@end

@interface TTotheJsonModel(Signal)

-(void)sendSignal:(id)sender;
@end

NS_ASSUME_NONNULL_END
